package mazeviejuno;

public class Map {
	private int width = 1;
	private int height = 1;
	private Cell[][] map;
	
	public Map(int width, int height) {
		this.width = width;
		this.height = height;
		this.map = new Cell[width][height];
		
		for (int i = 0; i < width; i++)
			for (int j = 0; j < height; j++) {
				this.map[i][j] = new Cell(i,j);
			}
	}
	
	public Cell getNextFreeCell() {
		for (int i = 0; i < this.width; i++) 
			for (int j = 0; j < this.height; j++)
				if (!this.map[i][j].isUsed)
					return this.map[i][j];
		return null;
	}

	public Cell getCell(int i, int j) {
		return this.map[i][j];
	}

	public void breakBond(Cell cell, int rnd) {
		System.out.println("Breaking bond at: (" + cell.getXpos() + "," + cell.getYpos() + ") in direction: " + rnd);
		cell.open(rnd);
		switch(rnd) {
		case 0: this.map[cell.getXpos()][cell.getYpos()-1].open(2); break;
		case 1: this.map[cell.getXpos()+1][cell.getYpos()].open(3); break;
		case 2: this.map[cell.getXpos()][cell.getYpos()+1].open(0); break;
		case 3: this.map[cell.getXpos()-1][cell.getYpos()].open(1); break;
		}
	}

	public int getWidth() {
		return this.width;
	}
	
	public int getHeight() {
		return this.height;
	}
	
	
	
}
